<div class="modal-header">
  <button type="button" class="close" data-dismiss="modal" aria-label="关闭"><span aria-hidden="true">&times;</span></button>
  <h4 class="modal-title" id="common-modal-label">
  	<span class="btn-group" id="classes-group"></span>
  </h4>
</div>
<div class="modal-body">
	<div id="calendar"></div>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
</div>

<script type="text/javascript">
<!--
	// 取消签到或请假
	function handlerUndo(trigger){
		jQuery.message.confirm("确定要"+trigger.innerText+"？", function(confirm){
			if(confirm){
				var _opts = jQuery(trigger).data();
				jQuery.ajaxsend({
					url: _opts.url.replace("{dbname}",dbname),
					data: _opts.params,
					success: function(data){
						if(data && data.success){
							jQuery("#calendar").fullCalendar("refetchEvents");
						}
					}
				});
			}
		});
	}
	
	// 加载班级日历数据
	var urlmap = {"签到":"/miwawa/{dbname}/student/check/undo", "缺勤":"/miwawa/{dbname}/student/check/undo", "请假":"/miwawa/{dbname}/student/leave/undo"};
	var statusmap = {"签到":"取消签到", "缺勤":"取消缺勤", "请假":"取消请假"};
	
	function loaderClasses(trigger, item){
		var studentid = trigger.id;
		
		if(jQuery("#calendar").html() == ""){
			require(['jquery.plugin.calendar'], function(calendar){
				calendar({
					displayEventTime:false,
					eventRender:function(event,element,view){
						element.attr("tabindex","0");
						element.attr("role","button");
						element.attr("data-placement","top");
						element.text(event.title+" "+event.actor+" "+(event.status));
						
						switch(event.status){
							case "请假": element.addClass("warning"); return;
							case "缺勤": element.addClass("danger"); return;
						}
					},
					eventAfterRender:function(event,element,view) {
						element.popover({
		        	content: "于["+event.actorDate+"] "+(event.status),
		        	template: "<div class='popover' role='tooltip'>"
		        					+ 	"<div class='arrow'></div>"
		        					+ 	"<div class='popover-toolbar'>"
		        					+			"<a class='btn btn-default btn-sm pull-left'><i class='"+(event.actor && event.actor.split(":")[0] == "家长" ? "icon-user-female" : "icon-user")+"'></i> "+event.actor+"</a>"
		        					+			"<a class='btn btn-danger btn-sm' onclick='handlerUndo(this, \""+event.checkDate+"\")' data-url='"+urlmap[event.status]+"' data-params='"+JSON.stringify(event)+"'>"+statusmap[event.status]+"</a>"
		        					+		"</div> "
		        					+ 	"<div class='popover-content'></div>"
		        					+ "</div>"
		        });
					},
					events:{
						url: "/miwawa/{dbname}/student/check/history".replace("{dbname}",dbname),
		        type: 'POST',
		        cache: false,
		        data:{
		        	"item": item,
		        	"invalid": "F",
		        	"studentId": studentid
		        },
		        success: function(data){ }
					}
				});
			});
		}
	}
//-->
</script>